|
1
|
|
|
/** global: chrome */ |
|
2
|
|
|
/** global: browser */ |
|
3
|
|
|
|
|
4
|
|
|
var func = tabs => { |
|
5
|
|
|
( chrome || browser ).runtime.sendMessage({ |
|
6
|
|
|
id: 'get_apps', |
|
7
|
|
|
tab: tabs[0], |
|
8
|
|
|
source: 'popup.js' |
|
9
|
|
|
}, response => { |
|
10
|
|
|
replaceDomWhenReady(appsToDomTemplate(response)); |
|
11
|
|
|
}); |
|
12
|
|
|
}; |
|
13
|
|
|
|
|
14
|
|
|
try { |
|
15
|
|
|
// Chrome, Firefox |
|
16
|
|
|
browser.tabs.query({ active: true, currentWindow: true }) |
|
17
|
|
|
.then(func) |
|
18
|
|
|
.catch(console.error); |
|
19
|
|
|
} catch ( e ) { |
|
20
|
|
|
// Edge |
|
21
|
|
|
browser.tabs.query({ active: true, currentWindow: true }, func); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
function replaceDomWhenReady(dom) { |
|
25
|
|
|
if ( /complete|interactive|loaded/.test(document.readyState) ) { |
|
26
|
|
|
replaceDom(dom); |
|
27
|
|
|
} else { |
|
28
|
|
|
document.addEventListener('DOMContentLoaded', () => { |
|
29
|
|
|
replaceDom(dom); |
|
30
|
|
|
}); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function replaceDom(domTemplate) { |
|
35
|
|
|
var body = document.body; |
|
36
|
|
|
|
|
37
|
|
|
while ( body.firstChild ) { |
|
38
|
|
|
body.removeChild(body.firstChild); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
body.appendChild(jsonToDOM(domTemplate, document, {})); |
|
42
|
|
|
|
|
43
|
|
|
var nodes = document.querySelectorAll('[data-i18n]'); |
|
44
|
|
|
|
|
45
|
|
|
for ( let ms = 200; ms < 500; ms += 50 ) { |
|
46
|
|
|
setTimeout(() => { |
|
47
|
|
|
let div = document.createElement('div'); |
|
48
|
|
|
|
|
49
|
|
|
div.style.display = 'none'; |
|
50
|
|
|
|
|
51
|
|
|
body.appendChild(div); |
|
52
|
|
|
}, ms); |
|
53
|
|
|
}; |
|
54
|
|
|
|
|
55
|
|
|
Array.prototype.forEach.call(nodes, node => { |
|
56
|
|
|
node.childNodes[0].nodeValue = browser.i18n.getMessage(node.dataset.i18n); |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
function appsToDomTemplate(response) { |
|
61
|
|
|
var |
|
62
|
|
|
appName, confidence, version, categories, |
|
63
|
|
|
template = []; |
|
64
|
|
|
|
|
65
|
|
|
if ( response.tabCache && Object.keys(response.tabCache.detected).length > 0 ) { |
|
66
|
|
|
for ( appName in response.tabCache.detected ) { |
|
67
|
|
|
confidence = response.tabCache.detected[appName].confidenceTotal; |
|
68
|
|
|
version = response.tabCache.detected[appName].version; |
|
69
|
|
|
categories = []; |
|
70
|
|
|
|
|
71
|
|
|
response.apps[appName].cats.forEach(cat => { |
|
72
|
|
|
categories.push( |
|
73
|
|
|
[ |
|
74
|
|
|
'a', { |
|
75
|
|
|
target: '_blank', |
|
76
|
|
|
href: 'https://wappalyzer.com/categories/' + slugify(response.categories[cat].name) |
|
77
|
|
|
}, [ |
|
78
|
|
|
'span', { |
|
79
|
|
|
class: 'category' |
|
80
|
|
|
}, [ |
|
81
|
|
|
'span', { |
|
82
|
|
|
class: 'name' |
|
83
|
|
|
}, |
|
84
|
|
|
browser.i18n.getMessage('categoryName' + cat) |
|
85
|
|
|
] |
|
86
|
|
|
] |
|
87
|
|
|
] |
|
88
|
|
|
); |
|
89
|
|
|
}); |
|
90
|
|
|
|
|
91
|
|
|
template.push( |
|
92
|
|
|
[ |
|
93
|
|
|
'div', { |
|
94
|
|
|
class: 'detected-app' |
|
95
|
|
|
}, [ |
|
96
|
|
|
'a', { |
|
97
|
|
|
target: '_blank', |
|
98
|
|
|
href: 'https://wappalyzer.com/applications/' + slugify(appName) |
|
99
|
|
|
}, [ |
|
100
|
|
|
'img', { |
|
101
|
|
|
src: '../images/icons/' + ( response.apps[appName].icon || 'default.svg' ) |
|
102
|
|
|
} |
|
103
|
|
|
], [ |
|
104
|
|
|
'span', { |
|
105
|
|
|
class: 'label' |
|
106
|
|
|
}, [ |
|
107
|
|
|
'span', { |
|
108
|
|
|
class: 'name' |
|
109
|
|
|
}, |
|
110
|
|
|
appName |
|
111
|
|
|
], |
|
112
|
|
|
( version ? ' ' + version : '' ) + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) |
|
113
|
|
|
] |
|
114
|
|
|
], |
|
115
|
|
|
categories |
|
116
|
|
|
] |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
} else { |
|
120
|
|
|
template = [ |
|
121
|
|
|
'div', { |
|
122
|
|
|
class: 'empty' |
|
123
|
|
|
}, |
|
124
|
|
|
browser.i18n.getMessage('noAppsDetected') |
|
125
|
|
|
]; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return template; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
function slugify(string) { |
|
132
|
|
|
return string.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-').replace(/(?:^-|-$)/, ''); |
|
133
|
|
|
} |
|
134
|
|
|
|